package com.android.tnovoselec.travelassistant;

import java.util.List;

import android.util.Log;

import com.android.tnovoselec.travelassistant.dto.MeteoFavoritesDto;
import com.google.android.maps.GeoPoint;
import com.nth.android.lbs.location.DistanceCalculator;

public class Util {
	
	public static MeteoFavoritesDto getNearestCityMeteoData(GeoPoint location, List<MeteoFavoritesDto> meteos){
		
		double dist = 0;
		MeteoFavoritesDto meteoToReturn = null;
		if (location == null){
			return meteoToReturn;
		}
		for (MeteoFavoritesDto meteo :meteos){
			double tempDist = DistanceCalculator.distance(location, new GeoPoint((int)(meteo.getLat()*1e6), (int)(meteo.getLng()*1e6)));
			if (Double.compare(dist, tempDist)>0 || Double.compare(dist, 0)==0){
				meteoToReturn = meteo;
				dist = tempDist;
			}
		}
		
		return meteoToReturn;
	}
	
	public static String getARTypeName(String type){		
		String retval="";
		if(type.indexOf(" ") ==-1 && type.indexOf("-")==-1){
			retval= type;
		} else {
			if(type.indexOf("-") !=-1 ){
				retval= type.substring(0, type.indexOf("-"));
			} else{
				retval= type.substring(0, type.indexOf(" "));
			}
		}
		Log.i("util", retval);
		return retval;
	}

}
